using System;
using System.Collections.Generic;
using System.Text;
using Diagram.Model;

namespace PetriDiagram.Model
{
    [Serializable]
    public class InhibitorArc : Relation
    {
        private PetriNetModel net;

        public InhibitorArc(PetriNetModel net)
            : base(net)
        {
            this.net = net;
        }

        //public override Entity Clone()
        //{
        //    return new InhibitorArc( net );
        //}

        public override Diagram.IUndoable GetInstance()
        {
            return new InhibitorArc( net );
        }

        public override bool IsValidRelationBetween(Entity start, Entity end)
        {
            if( !(start is Place && end is Transition) )
                return false;

            if( ExistConnection(start, end) )
                return false;

            return true;
        }

        private bool ExistConnection(Entity start, Entity end)
        {
            foreach( Relation r in net.Relations )
            {
                if( r.From == start && r.To == end && !r.Equals(this) )
                    return true;
            }

            return false;
        }

        public override bool CanStartWith( Entity start )
        {
            return ( start is Place && base.CanStartWith( start ) );
        }
    }
}
